<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><?php echo $button_cancel; ?></a></div>
    </div>
    <div class="content">
      <div id="tabs" class="htabs"><a href="#tab-data"><?php echo $tab_data; ?></a><a href="#tab-general"><?php echo $tab_general; ?></a><a href="#tab-links"><?php echo $tab_links; ?></a><a href="#tab-attribute"><?php echo $tab_attribute; ?></a><a href="#tab-option"><?php echo $tab_option; ?></a><a href="#tab-wholesale"><?php echo $tab_wholesale; ?></a><a href="#tab-promotion"><?php echo $tab_promotion; ?></a><a href="#tab-image"><?php echo $tab_image; ?></a></div>
      <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
        <div id="tab-data">
          <table class="form">
            <tr>
              <td><?php echo $entry_category; ?></td>
              <td><select name="category_id">
                  <?php foreach ($categories as $category) { ?>
                  <option value="<?php echo $category['category_id']; ?>" title="<?php echo $category['name']; ?>" <?php if($category['category_id'] == $category_id){ echo 'selected="selected"';} ?>><?php echo $category['display_name']; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_manufacturer; ?></td>
              <td><select name="manufacturer_id">
                  <option value="0" <?php if(0 == $manufacturer_id){ echo 'selected="selected"';} ?>><?php echo $text_none; ?></option>
                  <?php foreach ($manufacturers as $manufacturer) { ?>
                  <option value="<?php echo $manufacturer['manufacturer_id']; ?>" <?php if($manufacturer['manufacturer_id'] == $manufacturer_id){ echo 'selected="selected"';} ?>><?php echo $manufacturer['name']; ?></option>
                  <?php } ?>
                </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_name; ?></td>
              <td><input type="text" name="name" value="<?php echo $name; ?>"/></td>
            </tr>
            <tr>
              <td><?php echo $entry_ean; ?></td>
              <td><input type="text" name="ean" value="<?php echo $ean; ?>"/></td>
            </tr>
            <tr>
              <td><?php echo $entry_model; ?></td>
              <td><input type="text" name="model" value="<?php echo $model; ?>"/></td>
            </tr>
            <tr>
              <td><?php echo $entry_image; ?></td>
              <td><div class="image"><img src="<?php echo $thumb; ?>" alt="" id="thumb" /><br />
                  <input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
                  <a onclick="image_upload('image', 'thumb');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb').attr('src', '<?php echo $no_image; ?>'); $('#image').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
            </tr>
            <tr>
              <td><?php echo $entry_price; ?></td>
              <td><input type="text" name="price" value="<?php echo $price; ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_weight; ?></td>
              <td><input type="text" name="weight" value="<?php echo $weight; ?>" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_quantity; ?></td>
              <td><input type="text" name="quantity" value="<?php echo $quantity; ?>" size="2" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_minimum; ?></td>
              <td><input type="text" name="minimum" value="<?php echo $minimum; ?>" size="2" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_processing_day; ?></td>
              <td><input type="text" name="processing_day" value="<?php echo $processing_day; ?>" size="2"/></td>
            </tr>
            <tr>
              <td class="left"><?php echo $entry_layout; ?></td>
              <td class="left"><select name="layout_id">
                 <option value="0" <?php if(0 == $layout_id){ echo 'selected="selected"';} ?>><?php echo $text_none; ?></option>
                 <?php foreach ($layouts as $layout) { ?>
                 <option value="<?php echo $layout['layout_id']; ?>" <?php if($layout['layout_id'] == $layout_id){ echo 'selected="selected"';} ?>><?php echo $layout['name']; ?></option>
                 <?php } ?>
              </select></td>
            </tr>
            <tr>
              <td><?php echo $entry_sort_order; ?></td>
              <td><input type="text" name="sort_order" value="<?php echo $sort_order; ?>" size="2" /></td>
            </tr>
            <tr>
              <td><?php echo $entry_status; ?></td>
              <td>
              	<?php if ($status) { ?>
                <input name="status" type="radio" value="1" checked="checked"/><?php echo $text_enabled; ?>
                <input name="status" type="radio" value="0"/><?php echo $text_disabled; ?>
              	<?php } else { ?>
                <input name="status" type="radio" value="1"/><?php echo $text_enabled; ?>
                <input name="status" type="radio" value="0" checked="checked"/><?php echo $text_disabled; ?>
              	<?php } ?>
              </td>
            </tr>
          </table>
        </div>
        <div id="tab-general">
          <div id="languages" class="htabs">
            <?php foreach ($languages as $language) { ?>
            <a href="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
            <?php } ?>
          </div>
          <?php foreach ($languages as $language) { ?>
          <div id="language<?php echo $language['language_id']; ?>">
            <table class="form">
              <tr>
                <td><?php echo $entry_display_name; ?></td>
                <td><input type="text" name="product_description[<?php echo $language['language_id']; ?>][display_name]" size="100" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['display_name'] : ''; ?>" /></td>
              </tr>
              <tr>
                <td><?php echo $entry_meta_keyword; ?></td>
                <td><textarea name="product_description[<?php echo $language['language_id']; ?>][meta_keyword]" cols="100" rows="5"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['meta_keyword'] : ''; ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $entry_meta_description; ?></td>
                <td><textarea name="product_description[<?php echo $language['language_id']; ?>][meta_description]" cols="100" rows="5"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['meta_description'] : ''; ?></textarea></td>
              </tr>
              <tr>
                <td><?php echo $entry_tag; ?></td>
                <td><input type="text" name="product_description[<?php echo $language['language_id']; ?>][tag]" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['tag'] : ''; ?>" size="100" /></td>
              </tr>
              <tr>
                <td><?php echo $entry_description; ?></td>
                <td><textarea name="product_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['description'] : ''; ?></textarea></td>
              </tr>
            </table>
          </div>
          <?php } ?>
        </div>
        <div id="tab-links">
          <table class="form">
            <tr>
              <td><?php echo $entry_category_add; ?></td>
              <td>
                <div class="scrollbox">
                  <?php $class = 'odd'; ?>
                  <?php foreach ($categories as $category) { ?>
                  <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                  <div class="<?php echo $class; ?>">
                    <?php if (in_array($category['category_id'], $product_category)) { ?>
                    <input type="checkbox" name="product_category[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
                    <?php echo $category['display_name']; ?>
                    <?php } else { ?>
                    <input type="checkbox" name="product_category[]" value="<?php echo $category['category_id']; ?>" />
                    <?php echo $category['display_name']; ?>
                    <?php } ?>
                  </div>
                  <?php } ?>
                </div>
              </td>
            </tr>
            <tr>
              <td><?php echo $entry_related; ?></td>
              <td>
              	<?php echo $text_related_search; ?><input type="text" name="related" value="" /><br/>
              	<div id="product-related" class="scrollbox">
                  <?php $class = 'odd'; ?>
            	  <?php $pro_related_row = 0; ?>
                  <?php foreach ($product_related as $product_related) { ?>
                  <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                  <div id="product-related<?php echo $product_related['related_product_id']; ?>" class="<?php echo $class; ?>">
                    <input type="hidden" name="product_related[<?php echo $pro_related_row; ?>][related_product_id]" value="<?php echo $product_related['related_product_id']; ?>" />
                    <b><?php echo $entry_display_name; ?></b><?php echo '&nbsp;&nbsp;&nbsp;&nbsp;' . $product_related['display_name']; ?>&nbsp;&nbsp;&nbsp;&nbsp;
                    <b><?php echo $entry_price; ?></b><?php echo '&nbsp;&nbsp;&nbsp;&nbsp;'; ?><input type="text" name="product_related[<?php echo $pro_related_row; ?>][price]" value="<?php echo $product_related['price']; ?>" /><?php echo $product_related['price2']; ?>
                    <img src="view/image/delete.png" />
                  </div>
            	  <?php $pro_related_row++; ?>
                  <?php } ?>
                </div>
              </td>
            </tr>
          </table>
        </div>
        <div id="tab-attribute">
          <div id="vtab-attribute" class="vtabs">
            <?php $attribute_row = 0; ?>
            <?php foreach ($product_attributes as $product_attribute) { ?>
            <a href="#tab-attribute-<?php echo $attribute_row; ?>" id="attribute-<?php echo $attribute_row; ?>">
              <?php echo $product_attribute['name']; ?>&nbsp;
              <img src="view/image/delete.png" onclick="$('#vtab-attribute a:first').trigger('click'); $('#attribute-<?php echo $attribute_row; ?>').remove(); $('#tab-attribute-<?php echo $attribute_row; ?>').remove(); return false;" /></a>
            <?php $attribute_row++; ?>
            <?php } ?>
            <span id="attribute-add">
            <input type="text" name="attribute" value="" style="width: 130px;float:left;"/>
            &nbsp;<img src="view/image/add.png" alt="<?php echo $button_add_attribute; ?>" title="<?php echo $button_add_attribute; ?>" /></span>
          </div>
          <?php $attribute_row = 0; ?>
          <?php $attribute_value_row = 0; ?>
          <?php foreach ($product_attributes as $product_attribute) { ?>
          <div id="tab-attribute-<?php echo $attribute_row; ?>" class="vtabs-content">
            <input type="hidden" name="product_attribute[<?php echo $attribute_row; ?>][attribute_id]" value="<?php echo $product_attribute['attribute_id']; ?>" />
            <table class="form">
              <tr>
              	<td><?php echo $entry_attr_display_name; ?></td>
                <td><?php echo $product_attribute['display_name']; ?></td>
              	<td><?php echo $entry_attr_sort; ?></td>
                <td><input type="text" name="product_attribute[<?php echo $attribute_row; ?>][attr_sort]" value="<?php echo $product_attribute['attr_sort']; ?>" /></td>
                <td><?php echo $entry_attr_group_name; ?></td>
                <td><?php echo $product_attribute['group_name']; ?></td>
                <td><?php echo $entry_attr_group_display_name; ?></td>
                <td><?php echo $product_attribute['group_display_name']; ?></td>
              </tr>
            </table>
            <table id="attribute-value<?php echo $attribute_row; ?>" class="list">
              <thead>
                <tr>
                  <td class="left"><?php echo $entry_attr_value_name; ?></td>
                  <td class="left"><?php echo $entry_attr_value_display_name; ?></td>
                  <td class="left"><?php echo $entry_attr_value_sort; ?></td>
                  <td></td>
                </tr>
              </thead>
              <?php foreach ($product_attribute['product_attribute_value'] as $product_attribute_value) { ?>
              <tbody id="attribute-value-row<?php echo $attribute_value_row; ?>">
                <tr>
                  <td class="left">
                    <input type="hidden" name="product_attribute[<?php echo $attribute_row; ?>][product_attribute_value][<?php echo $attribute_value_row; ?>][attribute_value_id]" value="<?php echo $product_attribute_value['attribute_value_id']; ?>" />
            		<?php echo $product_attribute_value['name']; ?>
            	  </td>
                  <td class="left"><?php echo $product_attribute_value['display_name']; ?></td>
                  <td class="left"><input type="text" name="product_attribute[<?php echo $attribute_row; ?>][product_attribute_value][<?php echo $attribute_value_row; ?>][value_sort]" value="<?php echo $product_attribute_value['value_sort']; ?>" size="3" /></td>
                  <td class="left"><a onclick="$('#attribute-value-row<?php echo $attribute_value_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
                </tr>
              </tbody>
              <?php $attribute_value_row++; ?>
              <?php } ?>
              <tfoot>
                <tr>
                  <td colspan="3"></td>
                  <td class="left"><a onclick="addAattributeValue('<?php echo $attribute_row; ?>');" class="button"><?php echo $button_add_attr_value; ?></a></td>
                </tr>
              </tfoot>
            </table>
            <select id="attribute-values<?php echo $attribute_row; ?>" style="display: none;">
              <?php foreach ($product_attribute['attribute_value'] as $attribute_value) { ?>
              <option value="<?php echo $attribute_value['attribute_value_id']; ?>" avdn="<?php echo $attribute_value['display_name']; ?>" avs="<?php echo $attribute_value['sort_order']; ?>"><?php echo $attribute_value['name']; ?></option>
              <?php } ?>
            </select>
          </div>
          <?php $attribute_row++; ?>
          <?php } ?>
        </div>
        <div id="tab-option">
          <div id="vtab-option" class="vtabs">
            <?php $option_row = 0; ?>
            <?php foreach ($product_options as $product_option) { ?>
            <a href="#tab-option-<?php echo $option_row; ?>" id="option-<?php echo $option_row; ?>">
            	<?php echo $product_option['name']; ?>&nbsp;
            	<img src="view/image/delete.png" onclick="$('#vtab-option a:first').trigger('click'); $('#option-<?php echo $option_row; ?>').remove(); $('#tab-option-<?php echo $option_row; ?>').remove(); return false;" /></a>
            <?php $option_row++; ?>
            <?php } ?>
            <span id="option-add">
            <input name="option" value="" style="width: 130px;" />
            &nbsp;<img src="view/image/add.png" alt="<?php echo $button_add_option; ?>" title="<?php echo $button_add_option; ?>" /></span>
          </div>
          <?php $option_row = 0; ?>
          <?php $option_value_row = 0; ?>
          <?php foreach ($product_options as $product_option) { ?>
          <div id="tab-option-<?php echo $option_row; ?>" class="vtabs-content">
            <input type="hidden" name="product_option[<?php echo $option_row; ?>][option_id]" value="<?php echo $product_option['option_id']; ?>" />
            <table class="form">
              <tr>
                <td><?php echo $entry_option_display_name; ?></td>
                <td><?php echo $product_option['display_name']; ?></td>
                <td><?php echo $entry_option_type; ?></td>
                <td><?php echo $product_option['type']; ?></td>
                <td><?php echo $entry_required; ?></td>
                <td>
                  <?php if ($product_option['required']) { ?>
                  <input name="product_option[<?php echo $option_row; ?>][required]" type="radio" value="1" checked="checked"/><?php echo $text_yes; ?>
                  <input name="product_option[<?php echo $option_row; ?>][required]" type="radio" value="0"/><?php echo $text_no; ?>
              	  <?php } else { ?>
                  <input name="product_option[<?php echo $option_row; ?>][required]" type="radio" value="1"/><?php echo $text_yes; ?>
                  <input name="product_option[<?php echo $option_row; ?>][required]" type="radio" value="0" checked="checked"/><?php echo $text_no; ?>
              	  <?php } ?>
				</td>
                <td><?php echo $entry_option_sort; ?></td>
                <td><input type="text" name="product_option[<?php echo $option_row; ?>][option_sort]" value="<?php echo $product_option['option_sort']; ?>" size="3"/></td>
              </tr>
            </table>
            <table id="option-value<?php echo $option_row; ?>" class="list">
              <thead>
                <tr>
                  <td class="left"><?php echo $entry_option_value_name; ?></td>
                  <td class="left"><?php echo $entry_option_value_display_name; ?></td>
                  <td class="left"><?php echo $entry_option_value_sort; ?></td>
                  <td class="left"><?php echo $entry_option_value_price; ?></td>
                  <td class="left"><?php echo $entry_option_value_weight; ?></td>
                  <td class="left"><?php echo $entry_option_value_quantity; ?></td>
                  <td></td>
                </tr>
              </thead>
              <?php foreach ($product_option['product_option_value'] as $product_option_value) { ?>
              <tbody id="option-value-row<?php echo $option_value_row; ?>">
                <tr>
                  <td class="left">
                    <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][option_value_id]" value="<?php echo $product_option_value['option_value_id']; ?>" />
                    <?php echo $product_option_value['name']; ?>
                  </td>
                  <td class="left"><?php echo $product_option_value['display_name']; ?></td>
                  <td class="left">
                    <input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][value_sort]" value="<?php echo $product_option_value['value_sort']; ?>" size="3" />
                  </td>
                  <td class="left">
                    <input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][price]" value="<?php echo $product_option_value['price']; ?>" size="5" /></td>
                  </td>
                  <td class="left">
                    <input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][weight]" value="<?php echo $product_option_value['weight']; ?>" size="5" />
                  </td>
                  <td class="left"><input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][quantity]" value="<?php echo $product_option_value['quantity']; ?>" size="6" /></td>
                  <td class="left"><a onclick="$('#option-value-row<?php echo $option_value_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
                </tr>
              </tbody>
              <?php $option_value_row++; ?>
              <?php } ?>
              <tfoot>
                <tr>
                  <td colspan="6"></td>
                  <td class="left"><a onclick="addOptionValue('<?php echo $option_row; ?>');" class="button"><?php echo $button_add_option_value; ?></a></td>
                </tr>
              </tfoot>
            </table>
            <select id="option-values<?php echo $option_row; ?>" style="display: none;">
              <?php if (isset($product_option['option_value'])) { ?>
              <?php foreach ($product_option['option_value'] as $option_value) { ?>
              <option value="<?php echo $option_value['option_value_id']; ?>" ovdn="<?php echo $option_value['display_name']; ?>" ovs="<?php echo $option_value['sort_order']; ?>"><?php echo $option_value['name']; ?></option>
              <?php } ?>
              <?php } else { ?>
              <option value="0" ovdn="--" ovs="--">--</option>
              <?php } ?>
            </select>
          </div>
          <?php $option_row++; ?>
          <?php } ?>
        </div>
        <div id="tab-wholesale">
          <table id="wholesale" class="list">
            <thead>
              <tr>
                <td class="left"><?php echo $entry_wholesale_min_num; ?></td>
                <td class="left"><?php echo $entry_wholesale_max_num; ?></td>
                <td class="left"><?php echo $entry_wholesale_price; ?></td>
                <td></td>
              </tr>
            </thead>
            <?php $wholesale_row = 0; ?>
            <?php foreach ($product_wholesales as $product_wholesale) { ?>
            <tbody id="wholesale-row<?php echo $wholesale_row; ?>">
              <tr>
                <td class="left"><input type="text" name="product_wholesale[<?php echo $wholesale_row; ?>][min_num]" value="<?php echo $product_wholesale['min_num']; ?>" size="3"/></td>
                <td class="left"><input type="text" name="product_wholesale[<?php echo $wholesale_row; ?>][max_num]" value="<?php echo $product_wholesale['max_num']; ?>" size="3"/></td>
                <td class="left"><input type="text" name="product_wholesale[<?php echo $wholesale_row; ?>][price]" value="<?php echo $product_wholesale['price']; ?>" size="5"/></td>
                <td class="left"><a onclick="$('#wholesale-row<?php echo $wholesale_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
              </tr>
            </tbody>
            <?php $wholesale_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="3"></td>
                <td class="left"><a onclick="addwholesale();" class="button"><?php echo $button_add_wholesale; ?></a></td>
              </tr>
            </tfoot>
          </table>
        </div>
        <div id="tab-promotion">
          <table id="promotion" class="list">
            <thead>
              <tr>
                <td class="left"><?php echo $entry_promotion_name; ?></td>
                <td class="left"><?php echo $entry_promotion_display_name; ?></td>
                <td class="left"><?php echo $entry_promotion_status; ?></td>
                <td class="left"><?php echo $entry_promotion_start_time; ?></td>
                <td class="left"><?php echo $entry_promotion_end_time; ?></td>
                <td class="left"><?php echo $entry_product_promotion_price; ?></td>
                <td class="left"><?php echo $entry_product_promotion_quantity; ?></td>
                <td class="left"><?php echo $entry_product_promotion_start_time; ?></td>
                <td class="left"><?php echo $entry_product_promotion_end_time; ?></td>
                <td></td>
              </tr>
            </thead>
            <?php $promotion_row = 0; ?>
            <?php foreach ($product_promotions as $product_promotion) { ?>
            <tbody id="promotion-row<?php echo $promotion_row; ?>">
              <tr>
                <td class="left">
                  <input type="hidden" name="product_promotion[<?php echo $promotion_row; ?>][promotion_id]" value="<?php echo $product_promotion['promotion_id']; ?>" />
                  <?php echo $product_promotion['name']; ?>
                </td>
                <td class="left"><?php echo $product_promotion['display_name']; ?></td>
                <td class="left"><?php if ($product_promotion['status']) { echo $text_enabled; } else { echo $text_disabled; }?></td>
                <td class="left"><?php echo $product_promotion['start_time_2']; ?></td>
                <td class="left"><?php echo $product_promotion['end_time_2']; ?></td>
                <td class="left"><input type="text" name="product_promotion[<?php echo $promotion_row; ?>][price]" value="<?php echo $product_promotion['price']; ?>"/></td>
                <td class="left"><input type="text" name="product_promotion[<?php echo $promotion_row; ?>][quantity]" value="<?php echo $product_promotion['quantity']; ?>"/></td>
                <td class="left"><input type="text" name="product_promotion[<?php echo $promotion_row; ?>][start_time]" value="<?php echo $product_promotion['start_time']; ?>" class="date"/></td>
                <td class="left"><input type="text" name="product_promotion[<?php echo $promotion_row; ?>][end_time]" value="<?php echo $product_promotion['end_time']; ?>" class="date"/></td>
                <td class="left"><a onclick="$('#promotion-row<?php echo $promotion_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
              </tr>
            </tbody>
            <?php $promotion_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="9"></td>
                <td class="left"><a onclick="addpromotion();" class="button"><?php echo $button_add_promotion; ?></a></td>
              </tr>
            </tfoot>
          </table>
        </div>
        <div id="tab-image">
          <table id="images" class="list">
            <thead>
              <tr>
                <td class="left"><?php echo $entry_image; ?></td>
                <td class="left"><?php echo $entry_sort_order; ?></td>
                <td></td>
              </tr>
            </thead>
            <?php $image_row = 0; ?>
            <?php foreach ($product_images as $product_image) { ?>
            <tbody id="image-row<?php echo $image_row; ?>">
              <tr>
                <td class="left"><div class="image"><img src="<?php echo $product_image['thumb']; ?>" alt="" id="thumb<?php echo $image_row; ?>" />
                    <input type="hidden" name="product_image[<?php echo $image_row; ?>][image]" value="<?php echo $product_image['image']; ?>" id="image<?php echo $image_row; ?>" />
                    <br />
                    <a onclick="image_upload('image<?php echo $image_row; ?>', 'thumb<?php echo $image_row; ?>');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb<?php echo $image_row; ?>').attr('src', '<?php echo $no_image; ?>'); $('#image<?php echo $image_row; ?>').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
                <td class="left"><input type="text" name="product_image[<?php echo $image_row; ?>][sort_order]" value="<?php echo $product_image['sort_order']; ?>" size="2" /></td>
                <td class="left"><a onclick="$('#image-row<?php echo $image_row; ?>').remove();" class="button"><?php echo $button_remove; ?></a></td>
              </tr>
            </tbody>
            <?php $image_row++; ?>
            <?php } ?>
            <tfoot>
              <tr>
                <td colspan="2"></td>
                <td class="left"><a onclick="addImage();" class="button"><?php echo $button_add_image; ?></a></td>
              </tr>
            </tfoot>
          </table>
        </div>
      </form>
    </div>
  </div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script> 
<script type="text/javascript"><!--
<?php foreach ($languages as $language) { ?>
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
<?php } ?>
//--></script> 
<script type="text/javascript"><!--	
var pro_related_row = <?php echo $pro_related_row; ?>;
$('input[name=\'related\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=product/product/autocompleteRelated&token=<?php echo $token; ?>&filter_product_id=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.display_name,
						value: item.related_product_id,
						price: item.price
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('#product-related' + ui.item.value).remove();
		$('#product-related').append('<div id="product-related' + ui.item.value + '"><input type="hidden" name="product_related[' + 
				pro_related_row + '][related_product_id]" value="' + ui.item.value + '" /><b><?php echo $column_display_name; ?>：</b>&nbsp;&nbsp;&nbsp;&nbsp;' + ui.item.label + '&nbsp;&nbsp;&nbsp;&nbsp;<b><?php echo $column_price; ?>：</b>&nbsp;&nbsp;&nbsp;&nbsp;' + 
				'<input type="text" name="product_related[' + pro_related_row + '][price]" value="' + 
				ui.item.price + '" />' + ui.item.price + '<img src="view/image/delete.png" /></div>');
		$('#product-related div:odd').attr('class', 'odd');
		$('#product-related div:even').attr('class', 'even');
		pro_related_row++;		
		return false;
	},
	focus: function(event, ui) {
      return false;
    }
});
$('#product-related div img').live('click', function() {
	$(this).parent().remove();
	$('#product-related div:odd').attr('class', 'odd');
	$('#product-related div:even').attr('class', 'even');	
});
//--></script> 
<script type="text/javascript"><!--
var attribute_row = <?php echo $attribute_row; ?>;
$('input[name=\'attribute\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=product/attribute/autocomplete&token=<?php echo $token; ?>&filter_display_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.display_name,
						value: item.attribute_id,
						name: item.name,
						group_name: item.group_name,
						group_display_name: item.group_display_name,
						attribute_values: item.attribute_values
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		html  = '<div id="tab-attribute-' + attribute_row + '" class="vtabs-content">';
		html += '	<input type="hidden" name="product_attribute[' + attribute_row + '][attribute_id]" value="' + ui.item.value + '" />';
		html += '	<table class="form">';
		html += '	  <tr>';
		html += '		<td class="left"><?php echo $entry_attr_display_name; ?></td>';
		html += '       <td class="left">' + ui.item.label + '</td>';
		html += '		<td class="left"><?php echo $entry_attr_sort; ?></td>';
		html += '       <td class="left"><input type="text" name="product_attribute[' + attribute_row + '][attr_sort]" value="0"/></td>';
		html += '		<td class="left"><?php echo $entry_attr_group_name; ?></td>';
		html += '       <td class="left">' + ui.item.group_name + '</td>';
		html += '		<td class="left"><?php echo $entry_attr_group_display_name; ?></td>';
		html += '       <td class="left">' + ui.item.group_display_name + '</td>';
		html += '     </tr>';
		html += '  </table>';
		html += '  <table id="attribute-value' + attribute_row + '" class="list">';
		html += '  	 <thead>'; 
		html += '      <tr>';
		html += '        <td class="left"><?php echo $entry_attr_value_name; ?></td>';
		html += '        <td class="left"><?php echo $entry_attr_value_display_name; ?></td>';
		html += '        <td class="left"><?php echo $entry_attr_value_sort; ?></td>';
		html += '        <td></td>';
		html += '      </tr>';
		html += '  	 </thead>';
		html += '    <tfoot>';
		html += '      <tr>';
		html += '        <td colspan="3"></td>';
		html += '        <td class="left"><a onclick="addAattributeValue(' + attribute_row + ');" class="button"><?php echo $button_add_attr_value; ?></a></td>';
		html += '      </tr>';
		html += '    </tfoot>';
		html += '  </table>';
        html += '  <select id="attribute-values' + attribute_row + '" style="display: none;">';
        for (i = 0; i < ui.item.attribute_values.length; i++) {
			html += '  <option value="' + ui.item.attribute_values[i]['attribute_value_id'] + 
				'" avdn="' + ui.item.attribute_values[i]['display_name'] + '" avs="' + 
				ui.item.attribute_values[i]['sort_order'] + '">' + ui.item.attribute_values[i]['display_name'] + '</option>';
        }
        html += '  </select>';			
		html += '</div>';	
		$('#tab-attribute').append(html);
		$('#attribute-add').before('<a href="#tab-attribute-' + attribute_row + '" id="attribute-' + attribute_row + '">' + ui.item.name + 
				'&nbsp;<img src="view/image/delete.png" onclick="$(\'#vtab-attribute a:first\').trigger(\'click\'); $(\'#attribute-' + 
				attribute_row + '\').remove(); $(\'#tab-attribute-' + attribute_row + '\').remove(); return false;" /></a>');
		$('#vtab-attribute a').tabs();
		$('#attribute-' + attribute_row).trigger('click');
			
		attribute_row++;
		return false;
	},
	focus: function(event, ui) {
      return false;
   }
});
//--></script>
<script type="text/javascript"><!--	
var attribute_value_row = <?php echo $attribute_value_row; ?>;
function addAattributeValue(attribute_row) {	
	html  = '<tbody id="attribute-value-row' + attribute_value_row + '">';
	html += '  <tr>';
	html += '    <td class="left"><select id="selectAttrValue' + attribute_value_row  + '" onchange="changeAttrValue(' + attribute_value_row  + ')" name="product_attribute[' + attribute_row + '][product_attribute_value][' + attribute_value_row + '][attribute_value_id]">';
	html += $('#attribute-values' + attribute_row).html();
	html += '    </select></td>';
	html += '    <td class="left"></td>'; 
	html += '    <td class="left"><input type="text" name="product_attribute[' + attribute_row + '][product_attribute_value][' + attribute_value_row + '][value_sort]" value="0" size="3" /></td>';
	html += '    <td class="left"><a onclick="$(\'#attribute-value-row' + attribute_value_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#attribute-value' + attribute_row + ' tfoot').before(html);
	changeAttrValue(attribute_value_row);
	attribute_value_row++;
}
function changeAttrValue(attr_value_row){
	$optionSelect = '#selectAttrValue' + attr_value_row + ' option:selected';
	$optSelectObj = $($optionSelect);
	$tdObj = $optSelectObj.parent().parent().next().first();
	$tdObj.text($optSelectObj.attr('avdn'));
	$tdObj.next().first().children().first().val($optSelectObj.attr('avs'));
}
//--></script>
<script type="text/javascript"><!--	
var option_row = <?php echo $option_row; ?>;
$('input[name=\'option\']').autocomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=product/option/autocomplete&token=<?php echo $token; ?>&filter_display_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item.display_name,
						value: item.option_id,
						type: item.type,
						name: item.name,
						type: item.type,
						option_values: item.option_values
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		html  = '<div id="tab-option-' + option_row + '" class="vtabs-content">';
		html += '	<input type="hidden" name="product_option[' + option_row + '][option_id]" value="' + ui.item.value + '"/>';
		html += '	<table class="form">';
		html += '	  <tr>';
		html += '		<td class="left"><?php echo $entry_option_display_name; ?></td>';
		html += '       <td class="left">' + ui.item.label + '</td>';
		html += '		<td class="left"><?php echo $entry_option_type; ?></td>';
		html += '       <td class="left">' + ui.item.type + '</td>';
		html += '		<td class="left"><?php echo $entry_required; ?></td>';
		html += '       <td class="left"><input name="product_option[' + option_row + '][required]" type="radio" value="1" checked="checked"/><?php echo $text_yes; ?>';
		html += '<input name="product_option[' + option_row + '][required]" type="radio" value="0"/><?php echo $text_no; ?>';
		html += '	    </td>';
		html += '		<td class="left"><?php echo $entry_option_sort; ?></td>';
		html += '       <td class="left"><input name="product_option[' + option_row + '][option_sort]" type="text" value="0"/></td>';
		html += '     </tr>';
		html += '  </table>';
		html += '  <table id="option-value' + option_row + '" class="list">';
		html += '  	 <thead>'; 
		html += '      <tr>';
		html += '        <td class="left"><?php echo $entry_option_value_name; ?></td>';
		html += '        <td class="left"><?php echo $entry_option_value_display_name; ?></td>';
		html += '        <td class="left"><?php echo $entry_option_value_sort; ?></td>';
		html += '        <td class="left"><?php echo $entry_option_value_price; ?></td>';
		html += '        <td class="left"><?php echo $entry_option_value_weight; ?></td>';
		html += '        <td class="left"><?php echo $entry_option_value_quantity; ?></td>';
		html += '        <td></td>';
		html += '      </tr>';
		html += '  	 </thead>';
		html += '    <tfoot>';
		html += '      <tr>';
		html += '        <td colspan="6"></td>';
		html += '        <td class="left"><a onclick="addOptionValue(' + option_row + ');" class="button"><?php echo $button_add_option_value; ?></a></td>';
		html += '      </tr>';
		html += '    </tfoot>';
		html += '  </table>';
        html += '  <select id="option-values' + option_row + '" style="display: none;">';
        if(ui.item.option_values != null && ui.item.option_values.length > 0){
	        for (i = 0; i < ui.item.option_values.length; i++) {
				html += '  <option value="' + ui.item.option_values[i]['option_value_id'] + '" ovdn="' + ui.item.option_values[i]['display_name'] + 
					'" ovs="' + ui.item.option_values[i]['sort_order'] + '">' + ui.item.option_values[i]['name'] + '</option>';
	        }
        }else{
        	html += '  <option value="0" ovdn="--" ovs="--">--</option>';
        }
        html += '  </select>';			
		html += '</div>';
		
		$('#tab-option').append(html);
		$('#option-add').before('<a href="#tab-option-' + option_row + '" id="option-' + option_row + '">' + ui.item.name + 
				'&nbsp;<img src="view/image/delete.png" onclick="$(\'#vtab-option a:first\').trigger(\'click\'); $(\'#option-' + option_row + '\').remove(); $(\'#tab-option-' + option_row + '\').remove(); return false;" /></a>');
		$('#vtab-option a').tabs();
		$('#option-' + option_row).trigger('click');
		option_row++;
		return false;
	},
	focus: function(event, ui) {
      return false;
   }
});
//--></script> 
<script type="text/javascript"><!--		
var option_value_row = <?php echo $option_value_row; ?>;
function addOptionValue(option_row) {	
	html  = '<tbody id="option-value-row' + option_value_row + '">';
	html += '  <tr>';
	html += '    <td class="left"><select id="selectOptionValue' + option_value_row  + '" onchange="changeOptionValue(' + option_value_row  + ')" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][option_value_id]">';
	html += $('#option-values' + option_row).html();
	html += '    </select></td>';
	html += '    <td class="left"></td>'; 
	html += '    <td class="left"><input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][value_sort]" value="0"></td>';
	html += '    <td class="left">';
	html += '    <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][price]" value="0.00" size="5" /></td>';
	html += '    <td class="left">';
	html += '    <input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][weight]" value="0.00" size="5" /></td>';	
	html += '    <td class="left"><input type="text" name="product_option[' + option_row + '][product_option_value][' + option_value_row + '][quantity]" value="100" size="5" /></td>';
	html += '    <td class="left"><a onclick="$(\'#option-value-row' + option_value_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#option-value' + option_row + ' tfoot').before(html);
	changeOptionValue(option_value_row);
	option_value_row++;
}
function changeOptionValue(option_value_row){
	$optionSelect = '#selectOptionValue' + option_value_row + ' option:selected';
	$optSelectObj = $($optionSelect);
	$tdObj = $optSelectObj.parent().parent().next().first();
	$tdObj.text($optSelectObj.attr('ovdn'));
	$tdObj.next().first().children().first().val($optSelectObj.attr('ovs'));
}
//--></script> 
<script type="text/javascript"><!--
var wholesale_row = <?php echo $wholesale_row; ?>;
function addwholesale() {
	html  = '<tbody id="wholesale-row' + wholesale_row + '">';
	html += '  <tr>'; 
    html += '    <td class="left"><input type="text" name="product_wholesale[' + wholesale_row + '][min_num]" value="" size="3"/></td>';
	html += '    <td class="left"><input type="text" name="product_wholesale[' + wholesale_row + '][max_num]" value="" size="3"/></td>';
	html += '    <td class="left"><input type="text" name="product_wholesale[' + wholesale_row + '][price]" value="" size="5"/></td>';
	html += '    <td class="left"><a onclick="$(\'#wholesale-row' + wholesale_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';	
    html += '</tbody>';
	$('#wholesale tfoot').before(html);
	wholesale_row++;
}
//--></script> 
<script type="text/javascript"><!--
var promotion_row = <?php echo $promotion_row; ?>;
function addpromotion() {
	html  = '<tbody id="promotion-row' + promotion_row + '">';
	html += '  <tr>'; 
	html += '    <td class="left"><select id="selectPromotion' + promotion_row + '" onchange="changePromotion(' + promotion_row + ')" name="product_promotion[' + promotion_row + '][promotion_id]">';
    <?php foreach ($promotions as $promotion) { ?>
    html += '<option value="<?php echo $promotion['promotion_id']; ?>" pdn="<?php echo $promotion['display_name']; ?>" pst="<?php echo $promotion['start_time']; ?>" pet="<?php echo $promotion['end_time']; ?>"><?php echo $promotion['name']; ?></option>';
    <?php } ?>
    html += '</select></td>';
    html += '    <td class="left"></td>';
	html += '    <td class="left"><?php echo $text_enabled; ?></td>';
    html += '    <td class="left"></td>';
    html += '    <td class="left"></td>';
    html += '    <td class="left"><input type="text" name="product_promotion[' + promotion_row + '][price]" value="<?php echo $price; ?>"/></td>';
    html += '    <td class="left"><input type="text" name="product_promotion[' + promotion_row + '][quantity]" value="<?php echo $quantity; ?>"/></td>';
    html += '    <td class="left"><input type="text" name="product_promotion[' + promotion_row + '][start_time]" value="" class="date"/></td>';
    html += '    <td class="left"><input type="text" name="product_promotion[' + promotion_row + '][end_time]" value="" class="date"/></td>';
	html += '    <td class="left"><a onclick="$(\'#promotion-row' + promotion_row + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';
    html += '</tbody>';
	$('#promotion tfoot').before(html);
	$('#promotion-row' + promotion_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});
	promotion_row++;
}
function changePromotion(promotion_row) {
	$optionSelect = '#selectPromotion' + promotion_row + ' option:selected';
	$optSelectObj = $($optionSelect);
	$tdObj = $optSelectObj.parent().parent().nextAll();
	$($tdObj[0]).text($optSelectObj.attr('pdn'));
	$($tdObj[2]).text($optSelectObj.attr('pst'));
	$($tdObj[3]).text($optSelectObj.attr('pet'));
	$($tdObj[6]).children().first().val($optSelectObj.attr('pst'));
	$($tdObj[7]).children().first().val($optSelectObj.attr('pet'));
}
//--></script> 
<script type="text/javascript"><!--
function image_upload(field, thumb) {
	$('#dialog').remove();
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	$('#dialog').dialog({
		title: '<?php echo $text_image_manager; ?>',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(text) {
						$('#' + thumb).replaceWith('<img src="' + text + '" alt="" id="' + thumb + '" />');
					}
				});
			}
		},	
		bgiframe: false,
		width: 800,
		height: 400,
		resizable: false,
		modal: false
	});
};
//--></script> 
<script type="text/javascript"><!--
var image_row = <?php echo $image_row; ?>;
function addImage() {
    html  = '<tbody id="image-row' + image_row + '">';
	html += '  <tr>';
	html += '    <td class="left"><div class="image"><img src="<?php echo $no_image; ?>" alt="" id="thumb' + image_row + '" /><input type="hidden" name="product_image[' + image_row + '][image]" value="" id="image' + image_row + '" /><br /><a onclick="image_upload(\'image' + image_row + '\', \'thumb' + image_row + '\');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$(\'#thumb' + image_row + '\').attr(\'src\', \'<?php echo $no_image; ?>\'); $(\'#image' + image_row + '\').attr(\'value\', \'\');"><?php echo $text_clear; ?></a></div></td>';
	html += '    <td class="left"><input type="text" name="product_image[' + image_row + '][sort_order]" value="" size="2" /></td>';
	html += '    <td class="left"><a onclick="$(\'#image-row' + image_row  + '\').remove();" class="button"><?php echo $button_remove; ?></a></td>';
	html += '  </tr>';
	html += '</tbody>';
	$('#images tfoot').before(html);
	image_row++;
}
//--></script> 
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
//--></script> 
<script type="text/javascript"><!--
$('#tabs a').tabs(); 
$('#languages a').tabs(); 
$('#vtab-attribute a').tabs();
$('#vtab-option a').tabs();
//--></script> 
<?php echo $footer; ?>